package com.wlf.mq.customer;

import com.wlf.entity.MqMessage;
import com.wlf.entity.User;
import com.wlf.service.IMqMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lingfeng.wei
 * @date 2021/7/5 11:38
 */
@Component
@RabbitListener(queues ="${ut.order.queue}")
public class OrderReceiver{
    private static Logger logger = LoggerFactory.getLogger(OrderReceiver.class);

    @Autowired
    private IMqMessageService mqMessageService;

    @RabbitHandler
    public void onMessage(String msg) {
        try{
            logger.info("消费者收到order queue消息:{}",msg);
            User user =com.alibaba.fastjson.JSONObject.parseObject(msg, User.class);
            MqMessage mqMessage =new MqMessage();
            mqMessage.setBusinessId(String.valueOf(user.getId()));
            mqMessageService.updateMqMessageStatus(mqMessage);
            logger.info("mq local 信息表更新成功");
        }catch (Exception e){
            logger.info("mq消费失败",e);
        }
    }
}
